package com.example.springboot4.system.util;

/**
 * 媒体类型工具类
 *
 * @author 宋义州
 * @since 2024/1/16 16:42
 */
public class MimeTypeUtils {

    public static final String IMAGE_PNG = "image/png";

    public static final String IMAGE_JPG = "image/jpg";

    public static final String IMAGE_JPEG = "image/jpeg";

    public static final String IMAGE_BMP = "image/bmp";

    public static final String IMAGE_GIF = "image/gif";

    /**
     * 图片后缀
     */
    public static final String[] IMAGE_EXTENSION = {"bmp", "gif", "jpg", "jpeg", "png"};

    /**
     * flash后缀
     */
    public static final String[] FLASH_EXTENSION = {"swf", "flv"};

    /**
     * 媒体后缀
     */
    public static final String[] MEDIA_EXTENSION = {"swf", "flv", "mp3", "wav", "wma", "wmv", "mid", "avi", "mpg", "asf", "rm", "rmvb"};

    /**
     * 视频后缀
     */
    public static final String[] VIDEO_EXTENSION = {"mp4", "avi", "rmvb"};

    /**
     * 默认允许上传的文件后缀
     */
    public static final String[] DEFAULT_ALLOWED_EXTENSION = {
            // 图片
            "bmp", "gif", "jpg", "jpeg", "png",
            // word excel powerpoint pdf
            "doc", "docx", "xls", "xlsx", "ppt", "pptx", "html", "htm", "txt", "pdf",
            // 压缩文件
            "rar", "zip", "gz", "bz2", "7z", "tar",
            // 视频格式
            "mp4", "avi", "rmvb"
    };

    /**
     * 获取文件后缀
     *
     * @param prefix 文件前缀
     * @return 后缀
     */
    public static String getExtension(String prefix) {
        return switch (prefix) {
            case IMAGE_PNG -> "png";
            case IMAGE_JPG -> "jpg";
            case IMAGE_JPEG -> "jpeg";
            case IMAGE_BMP -> "bmp";
            case IMAGE_GIF -> "gif";
            default -> "";
        };
    }

}
